
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/17/2011 22:38:09
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [twitter];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MemberTweet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TweetJeu] DROP CONSTRAINT [FK_MemberTweet];
GO
IF OBJECT_ID(N'[dbo].[FK_UserTweet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TweetJeu] DROP CONSTRAINT [FK_UserTweet];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserJeu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserJeu];
GO
IF OBJECT_ID(N'[dbo].[TweetJeu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TweetJeu];
GO
IF OBJECT_ID(N'[dbo].[MemberJeu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberJeu];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserJeu'
CREATE TABLE [dbo].[UserJeu] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [screenName] nvarchar(max)  NOT NULL,
    [name] nvarchar(max)  NULL,
    [userId] nvarchar(max)  NULL,
    [profileUrl] nvarchar(max)  NULL
);
GO

-- Creating table 'TweetJeu'
CREATE TABLE [dbo].[TweetJeu] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [text] nvarchar(max)  NOT NULL,
    [creationDate] datetime  NOT NULL,
    [imgUrl] nvarchar(max)  NULL,
    [Member_ID] int  NOT NULL,
    [User_ID] int  NOT NULL
);
GO

-- Creating table 'MemberJeu'
CREATE TABLE [dbo].[MemberJeu] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [login] nvarchar(max)  NOT NULL,
    [password] nvarchar(max)  NOT NULL,
    [name] nvarchar(max)  NULL,
    [email] nvarchar(max)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'UserJeu'
ALTER TABLE [dbo].[UserJeu]
ADD CONSTRAINT [PK_UserJeu]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TweetJeu'
ALTER TABLE [dbo].[TweetJeu]
ADD CONSTRAINT [PK_TweetJeu]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MemberJeu'
ALTER TABLE [dbo].[MemberJeu]
ADD CONSTRAINT [PK_MemberJeu]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Member_ID] in table 'TweetJeu'
ALTER TABLE [dbo].[TweetJeu]
ADD CONSTRAINT [FK_MemberTweet]
    FOREIGN KEY ([Member_ID])
    REFERENCES [dbo].[MemberJeu]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberTweet'
CREATE INDEX [IX_FK_MemberTweet]
ON [dbo].[TweetJeu]
    ([Member_ID]);
GO

-- Creating foreign key on [User_ID] in table 'TweetJeu'
ALTER TABLE [dbo].[TweetJeu]
ADD CONSTRAINT [FK_UserTweet]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[UserJeu]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserTweet'
CREATE INDEX [IX_FK_UserTweet]
ON [dbo].[TweetJeu]
    ([User_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------